package day03.am;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Demo01 {
    public static void main(String[] args) throws IOException {
        JFrame jFrame = new JFrame("捕鱼");
        jFrame.setSize(800,480);
        jFrame.setResizable(false);
        jFrame.setLocationRelativeTo(null);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        MyPanel myPanel = new MyPanel();
        jFrame.add(myPanel);

        jFrame.setVisible(true);
    }
}
//面板
class MyPanel extends JPanel{
    BufferedImage bg ;//定义背景图
    BufferedImage[] fish;
    public MyPanel() throws IOException {
        //加载背景图片
        bg = ImageIO.read(new File("fish/images/bg.jpg"));
        fish = new BufferedImage[9+9];
        for(int i=0;i<9;i++){
            fish[i] = ImageIO.read(new File("fish/images/fish0"+(i+1)+"_00.png"));
            fish[i+9]=ImageIO.read(new File("fish/images/fish0"+(i+1)+"_00.png"));
        }
    }
    public void paint(Graphics g) {
        //将背景图绘制到面板上
        g.drawImage(bg,0,0,null);
        for(int i=0;i<fish.length;i++){
            g.drawImage(fish[i],
                    (int)(Math.random()*(800-fish[i].getWidth())),
                    (int)(Math.random()*(480-fish[i].getHeight())),null);
        }


    }
}